package com.example.test;

import com.sun.media.sound.SoftResampler;
import com.sun.media.sound.SoftResamplerStreamer;

import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;

public class Seven_Quote {
    public static void main(String args[]) {
        //强引用
        String s = "强 森！！仔";
        //软引用
        SoftReference<String> stringSoftReference =
                new SoftReference<>(new String("软 森！！仔"));
        System.out.println(stringSoftReference.get());
        System.gc();
        System.out.println(stringSoftReference.get());

        //弱引用
        WeakReference<String> str =
                new WeakReference<>(new String("弱 森！！仔"));
        System.out.println(str.get());
        System.gc(); //通知JVM进行内存回收
        System.out.println(str.get());

        //虚引用
        ReferenceQueue<Object> Queue = new ReferenceQueue<>();
        PhantomReference<String> strs =
                new PhantomReference<>("虚 森！！仔", Queue);
        System.out.println(strs.get());

        System.out.println(s);

    }
}
